package com.itheima.config;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import javax.servlet.Filter;

public class ServletInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer{
    //其他配置文件
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }
//拦截路径
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    //配置post请求乱码
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter cef = new CharacterEncodingFilter();
        cef.setEncoding("utf-8");
        return new Filter[]{cef};
    }
}
//把springmvcconfig配置文件加载到tomcat容器
//配置拦截路径 = 找到指定的controller映射路径
/*public class ServletInitConfig extends AbstractDispatcherServletInitializer {
    //把springmvcconfig配置文件加载到tomcat容器
    @Override
    protected WebApplicationContext createServletApplicationContext() {
        AnnotationConfigWebApplicationContext app = new AnnotationConfigWebApplicationContext();
        app.register(SpringMvcConfig.class);
        return app;
    }
    //配置拦截路径 = 找到指定的controller映射路径
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};//拦截路径
    }

    //其他资源配置
    @Override
    protected WebApplicationContext createRootApplicationContext() {
        AnnotationConfigWebApplicationContext app = new AnnotationConfigWebApplicationContext();
        app.register(SpringConfig.class);
        return app;
    }
}*/
